package com.mebs.model.reports;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import javax.persistence.Column;
import javax.persistence.Entity;

@Entity()
public class PdfReportTemplate {
	
	//shipment data section
	@Column(name = "Container", nullable = true)
	private boolean container;
	
	@Column(name = "Seal", nullable = true)
	private boolean seal;
	
	//table section
	@Column(name = "Reference", nullable = true)
	private boolean reference;
	
	@Column(name = "Po", nullable = true)
	private boolean po;
	
	@Column(name = "ECCN", nullable = true)
	private boolean eccn;
	
	@Column(name = "PN", nullable = true)
	private boolean pn;
	
	@Column(name = "SN", nullable = true)
	private boolean sn;
	
	@Column(name = "Weight", nullable = true)
	private boolean weight;
	
	@Column(name = "Dims", nullable = true)
	private boolean dims;
	
	@Column(name = "SchedBNumber", nullable = true)
	private boolean schedBNumber;
	
	@Column(name = "HtsNumber", nullable = true)
	private boolean htsNumber;
	
	public PdfReportTemplate() {
		super();
	}

	public boolean isContainer() {
		return container;
	}

	public void setContainer(boolean container) {
		this.container = container;
	}

	public boolean isSeal() {
		return seal;
	}

	public void setSeal(boolean seal) {
		this.seal = seal;
	}

	public boolean isReference() {
		return reference;
	}

	public void setReference(boolean reference) {
		this.reference = reference;
	}

	public boolean isPo() {
		return po;
	}

	public void setPo(boolean po) {
		this.po = po;
	}

	public boolean isEccn() {
		return eccn;
	}

	public void setEccn(boolean eccn) {
		this.eccn = eccn;
	}

	public boolean isPn() {
		return pn;
	}

	public void setPn(boolean pn) {
		this.pn = pn;
	}

	public boolean isSn() {
		return sn;
	}

	public void setSn(boolean sn) {
		this.sn = sn;
	}

	public boolean isWeight() {
		return weight;
	}

	public void setWeight(boolean weight) {
		this.weight = weight;
	}

	public boolean isDims() {
		return dims;
	}

	public void setDims(boolean dims) {
		this.dims = dims;
	}

	public boolean isSchedBNumber() {
		return schedBNumber;
	}

	public void setSchedBNumber(boolean schedBNumber) {
		this.schedBNumber = schedBNumber;
	}

	public boolean isHtsNumber() {
		return htsNumber;
	}

	public void setHtsNumber(boolean htsNumber) {
		this.htsNumber = htsNumber;
	}
	
	public int getColumnsNumber() {
		int columnNumber = 0;
		for (Method method : this.getClass().getMethods()) {
			if (!method.getName().startsWith("is") && 
					!method.getName().startsWith("get")) {
				continue;
			}
			
			String name = method.getName().startsWith("is") ? 
					method.getName().replace("is", "") :
					method.getName().replace("get", "");
			
			if ("seal".equalsIgnoreCase(name) ||
					"container".equalsIgnoreCase(name) ||
					"columnsNumber".equalsIgnoreCase(name)) {
				continue;
			}
			
			try {
				if (method.invoke(this) instanceof Boolean &&
						true == (Boolean)method.invoke(this)) {
					columnNumber++;
				}
			} catch (InvocationTargetException e) {
				e.printStackTrace();
			} catch (IllegalArgumentException e) {
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			}
		}
		return columnNumber;
	}
	
}
